// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    // API 调用都保持和云函数当前所在环境一致
    env: cloud.DYNAMIC_CURRENT_ENV
  })

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    const db = cloud.database()

    await db.collection('deviceid').add({
        // data 字段表示需新增的 JSON 数据
        data: {

            addtime: parseInt(new Date().getTime() / 1000),



            openid: wxContext.OPENID,
            appid: wxContext.APPID,
            unionid: wxContext.UNIONID,

            device_logicid:event.device_logicid,
            onenet_deviceid: event.onenet_deviceid,
              onenet_pid: event.onenet_pid,
              ondevice_key: event.ondevice_key,

        }
    })
    .then(res => {
        console.log(res)
        return {
            res
            
        }
    })
    .catch(err => {
        console.error(err)
    })

}